package com.yaowk.sfp.system.server.service.base;

import java.lang.Long;
import com.yaowk.sfp.system.server.entity.SysMenu;
import java.util.Date;
import com.yaowk.sfp.system.server.service.IMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import com.yaowk.sfp.common.db.BaseServiceImpl;
import com.yaowk.sfp.system.server.dao.MenuDao;
import java.lang.String;
import java.lang.Byte;
import com.yaowk.sfp.system.api.model.Menu;

public abstract class MenuServiceBase extends BaseServiceImpl<Menu, SysMenu, Long> implements IMenuService {

	@Autowired
	private MenuDao dao;

	@Override protected MenuDao getDao() {
	return dao;
	}

	@Override
	public Menu entity2Model(SysMenu entity) {
		Menu model = null;
		if(isNotEmpty(entity)){
			model = new Menu();
			model.setId(entity.getId());
			model.setName(entity.getName());
			model.setDescription(entity.getDescription());
			model.setUrl(entity.getUrl());
			model.setParentId(entity.getParentId());
			model.setSort(entity.getSort());
			model.setStatus(entity.getStatus());
			model.setType(entity.getType());
			model.setCreateTime(entity.getCreateTime());
		}
		return model;
	}

	@Override
	public SysMenu model2Entity(Menu model) {
		SysMenu entity = null;
		if(isNotEmpty(model)){
			entity = new SysMenu();
			entity.setId(model.getId());
			entity.setName(model.getName());
			entity.setDescription(model.getDescription());
			entity.setUrl(model.getUrl());
			entity.setParentId(model.getParentId());
			entity.setSort(model.getSort());
			entity.setStatus(model.getStatus());
			entity.setType(model.getType());
			entity.setCreateTime(model.getCreateTime());
		}
		return entity;
	}

	@Override
	public SysMenu updateParams(Menu model) {
		SysMenu entity = dao.findOne(model.getId());
		if(isNotEmpty(model.getName()))
			entity.setName(model.getName());
		if(isNotEmpty(model.getDescription()))
			entity.setDescription(model.getDescription());
		if(isNotEmpty(model.getUrl()))
			entity.setUrl(model.getUrl());
		if(isNotEmpty(model.getParentId()))
			entity.setParentId(model.getParentId());
		if(isNotEmpty(model.getSort()))
			entity.setSort(model.getSort());
		if(isNotEmpty(model.getStatus()))
			entity.setStatus(model.getStatus());
		if(isNotEmpty(model.getType()))
			entity.setType(model.getType());
		if(isNotEmpty(model.getCreateTime()))
			entity.setCreateTime(model.getCreateTime());
		return entity;
	}


}